import { Db } from 'mongodb'
import { UserInfo } from './types'

class User {
  private db: Db
  constructor(database: Db) {
    this.db = database
  }

  public async insertOne(name: string, age: number) {
    const user = this.db.collection<UserInfo>('users')
    const result = await user.insertOne({
      name,
      age
    })
    console.log(`A document was inserted with the _id: ${JSON.stringify(result)}`)
  }

}

//   public async findAllUser() {
//   const collection = this.db.collection('users')
//   const res = await collection.find().toArray()
//   console.log('所有用户', res)
// }

export default User